package com.maserb.monitor;

import com.maserb.monitor.remote.BrushCardService;
import com.maserb.monitor.remote.impl.BrushCardServiceImpl;
import com.maserb.monitor.runner.MonitorAppRunner;
import org.apache.cxf.Bus;
import org.apache.cxf.bus.spring.SpringBus;
import org.apache.cxf.jaxws.EndpointImpl;
import org.apache.cxf.transport.servlet.CXFServlet;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.web.servlet.MultipartConfigFactory;
import org.springframework.boot.web.servlet.ServletRegistrationBean;
import org.springframework.cache.annotation.EnableCaching;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.scheduling.annotation.EnableScheduling;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import javax.servlet.MultipartConfigElement;
import javax.xml.ws.Endpoint;

@EnableSwagger2
@SpringBootApplication
@EnableCaching
@Configuration
@EnableScheduling
public class MonitorApplication {

	public static void main(String[] args) {
		SpringApplication.run(MonitorApplication.class, args);
	}

	@Bean
	public MonitorAppRunner treeCacheRunner(){
		return new MonitorAppRunner();
	}

	@Bean
	public MultipartConfigElement multipartConfigElement() {
		MultipartConfigFactory factory = new MultipartConfigFactory();
		//  单个数据大小
		factory.setMaxFileSize("204800KB"); // KB,MB
		/// 总上传数据大小
		factory.setMaxRequestSize("204800KB");
		return factory.createMultipartConfig();
	}

	@Bean
	public ServletRegistrationBean disServlet() {
		return new ServletRegistrationBean(new CXFServlet(), "/services/*");
	}

	@Bean(name = Bus.DEFAULT_BUS_ID)
	public SpringBus springBus() {
		return new SpringBus();
	}

	@Bean
	public BrushCardService brushCardService() {
		return new BrushCardServiceImpl();
	}

	@Bean
	public Endpoint endpoint() {
		EndpointImpl endpoint = new EndpointImpl(springBus(), brushCardService());
		endpoint.publish("/BrushCardService");
		return endpoint;
	}
}